﻿package sprites {
	import org.flixel.FlxGroup;
	import org.flixel.FlxPoint;
	import org.flixel.FlxSprite;
	import org.flixel.FlxText;

	/**
	 * ...
	 * @author test
	 */
	public class Bar extends FlxGroup {
		public var _player:Player;
		public var _orig_len:uint;
		public var _color:Number;
		public var _back:FlxSprite;
		public var _front:FlxSprite;
		public var _text:FlxText;

		override public function update():void {
			if (_front != null){
				super.update();
				_front.scale.x = (_player.weapon._energy / _player.weapon._menergy);
			}
		}

		public function Bar(__text:String, __player:Player, __color:Number, __len:uint, __hei:uint, X:Number = 0, Y:Number = 0):void {
			super();
			_player = __player;
			_color = __color;
			_orig_len = __len;
			this.x = X;
			this.y = Y;
			this.scrollFactor = new FlxPoint(0, 0);

			_text = new FlxText(0, 0, __len, __text);
			_text.setFormat(null, 12, 0xffffff, "center");

			_back = new FlxSprite();
			_front = new FlxSprite();

			_front.y = _back.y = __hei + 20;

			_back.createGraphic(__len, __hei, 0xffffffff);
			_front.createGraphic(__len, __hei, __color);
			_front.origin.x = 0

			this.add(_back, true);
			this.add(_front, true);
			this.add(_text, true);
		}
	}

}